#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>


void childrun()
{
  int cnt = 5;
  while(cnt--){
    printf("I am a child process,PID:%d,PPID:%d,cnt:%d\n",getpid(),getppid(),cnt);
    sleep(1);
  }
}
int main()
{
  printf("this is father...\n");
  pid_t id = fork();
  if(id == 0 ){
    childrun();
    printf("child quit...\n");
    exit(1);
  }
  
    sleep(10);
    int status = 0;
    //pid_t rid = wait(NULL);
    pid_t rid = waitpid(id,&status,0);
    if(rid > 0){
      printf("wait success!! rid:%d,exit_code:%d,sign_code:%d\n",rid,status>>8,status&0x7F);
      sleep(1);
    }
    else{
      printf("wait failed!! \n");
    }
    printf("father quit...\n");

}
